﻿Ext.require(  
        [  
            'Ext.grid.*',  
            'Ext.toolbar.Paging',  
            'Ext.util.*',  
            'Ext.data.*',  
            //注意引用  
            'Ext.ux.form.SearchField'  
         ]          
); 

studentList = function(){	
Ext.define('MyData',{
	extend:'Ext.data.Model',
	id:'myData',
	fields:[
	        	{name:'id',type:'string'},
		        {name:'studentId',type:'string'},
		        {name:'studentName',type:'string'},
		        {name:'grade',type:'string'},
		        {name:'inclass',type:'string'},
		        {name:'remark',type:'string'},
		        {name:'photo',type:'string'},
		        {name:'phone',type:'string'},
		        {name:'email',type:'string'},
		        {name:'sex',type:'string'},
		        {name:'ago',type:'string'},
		        {name:'password',type:'string'},
		        {name:'academy',type:'string'},
		        {name:'professional',type:'string'}
		       ]
});
var reader = Ext.create('Ext.data.JsonReader',{
	root:'list',
	model:MyData
});
Ext.define('sourseData',{
	extend:'Ext.data.Model',
	id:'sourseDate',
	fields:[
	        	{name:'studentId',type:'string'},
		        {name:'StudentName',type:'string'},
		        {name:'courseName',type:'string'},
		        {name:'grade',type:'string'},
		        {name:'credit',type:'string'},
		        {name:'testScores',type:'string'},
		        {name:'peacetimeScores',type:'string'},
		        {name:'prom',type:'string'},
		        {name:'grade',type:'string'},
		        {name:'hourse',type:'string'},
		        {name:'isAgain',type:'string'},
		        {name:'scores',type:'string'}

		       ]
});
var store = Ext.create('Ext.data.Store',{
	pageSize:8,
	model:MyData,
	autoLoad:true,
	proxy:{
		type:'ajax',
		url:'searchStudentByTeacherIdAction.action',
		reader:{
			type:'json',
			root:'resultList.list',
			totalProperty:'resultList.total'
		}
	}
});

var sourseStore = Ext.create('Ext.data.Store',{
	//pageSize:8,
	model:sourseData,
	groupField: 'prom',
	//autoLoad:true,
	proxy:{
		type:'ajax',
		url:'searchSourseAction.action',
		reader:{
			type:'json',
			root:'studentCreditPojo.studentScores',
			//totalProperty:'resultList.total'
		}
	},
	listeners: {//为了编辑时设定初始值Ext.getCmp("fwz").setValue(2);  
        load: function(store,records) {        	
            Ext.getCmp('studentSourseNameId').setValue(store.proxy.reader.jsonData.studentCreditPojo.studentName);  
            Ext.getCmp('totalHourseId').setValue(store.proxy.reader.jsonData.studentCreditPojo.totalHourse);  
            Ext.getCmp('totalCreditId').setValue(store.proxy.reader.jsonData.studentCreditPojo.totalCredit);  
            Ext.getCmp('totalGetCreditId').setValue(store.proxy.reader.jsonData.studentCreditPojo.totalGetCredit);  
            
            
        }  
    }

});
var studentForm = Ext.create('Ext.FormPanel',{
	frame:true,
	waitMsgTarget:true,
	width:200,
	title:'信息',
	defaultType:'displayfield',
	reader:reader,
	//style:'padding-left:100px',
	 layout: {
	        type: 'absolute'
	    },
	items:[{
		fieldLabel:'编号',
		x:100,
		y:20,
		name:'id',
		hidden:true
	},{
		fieldLabel:'学号',
		name:'studentId',
		x:100,
		y:50,
		allowBlank:false
	},{
		fieldLabel:'姓名',
		name:'studentName',
		x:100,
		y:80,
		allowBlank:false
	},{
		fieldLabel:'年级',
		name:'grade',
		x:100,
		y:110,
		allowBlank:false
	},{
		fieldLabel:'学院',
		name:'academy',
		x:100,
		y:140,
		allowBlank:false
	},{
		fieldLabel:'专业',
		name:'professional',
		x:100,
		y:170,
		allowBlank:false
	},{
		fieldLabel:'班级',
		name:'inclass',
		x:100,
		y:200,
		allowBlank:false
	},{
		fieldLabel:'简介',
		xtype:'textareafield',
		name:'remark',
		width:450,
		height:70,
		readOnly:true,
		x:100,
		y:230,
		allowBlank:false
	},{
		fieldLabel:'联系电话',
		name:'phone',
		x:100,
		y:330,
		allowBlank:false
	},{
		fieldLabel:'邮箱',
		name:'email',
		x:100,
		y:360,
		allowBlank:false
	},{
		fieldLabel:'年龄',
		name:'ago',
		x:100,
		y:390,
		allowBlank:false
	},{
		fieldLabel:'性别',
		name:'sex',
		x:100,
		y:420,
		allowBlank:false
	},{
		fieldLabel:'',
		x:100,
		y:450,
		name:'photo',
		id:'photo',
		hidden:true
	},{
		xtype:'panel',
    	width:100,
    	height:130,
    	x:350,
		y:60,
    	style: 'clear:both;margin-left:37px;border:1px solid blue; margin-bottom:8px',
    	items:{
        xtype: 'box',
        id:'image',
        autoEl: {
            width: 100,         
           // style: '',
            tag: 'img'
            //src:findField("photo"),
            //id: 'user.save.photoshow.' + user.IntUserID,
           // src: (user.StrImagePath === '' || user.StrImagePath === undefined) ? nophone : user.StrImagePath
        }}
	}]
});
var checkBox = Ext.create('Ext.selection.CheckboxModel');
var grade = getStaticDataStore('grade');
var grid = Ext.create('Ext.grid.Panel',{
	store:store,	
	columnLines:true,
	selModel:checkBox,
	disableSelection:false,
	loadMask:true,
	columns:[
	         {text:'编号',width:50,dataIndex:'id',sortable:true},
	         {text:'学号',width:200,dataIndex:'studentId',sortable:true},
	         {text:'姓名',width:150,dataIndex:'studentName',sortable:true},
	         {text:"年级",width:150,dataIndex:'grade',sortable:true,renderer:function(v){
    			 var index = grade.find('valueId',v); 
    			 if(index != -1){
    				 var r = grade.getAt(index);
    				 return r.get("valueName");
    			 }
    			 else{
    				 return v;
    			 }
    		 }},
	         {text:"班级",width:150,dataIndex:'inclass',sortable:true},
	         {text:"简介",width:150,dataIndex:'remark',sortable:true}
	         ],
	autoHeight:true,
	authWidth:true,

	title:"学生选课信息",
	loadMask:true,
	pageSize:5,
	listeners:{  
        'itemdblclick' : function(grid, rowIndex, e){
        	editStudent();
        }
        },
	/*viewConfig:{
		id:'gv',
		trackOver:false,
		stripeRows:false,
	},*/
	dockedItems:[{
		dock:'top',
		xtype:'toolbar',
		
		items:[{
			width:300,
			fieldLabel:'搜索',
			labelWidth:70,
			xtype:'searchfield',
			store:store			
		},{
			xtype:'label',
			html:'<div style="font-size:12px;color:red">支持学号和姓名的模糊查询</div>'
		},'->',{
			text:'查看成绩',
			iconCls:'Applicationform',
			xtype:'button',
			handler:lookSourse
		},'-',{
			text:'详细信息',
			iconCls:'Applicationform',
			xtype:'button',
			handler:editStudent
		},'-',{
			text:'学生总结',
			iconCls:'Applicationform',
			xtype:'button',
			handler:function (){
				var selectedKeys = grid.getSelectionModel().getSelection();
				if(selectedKeys.length != 1){
					Ext.MessageBox.alert('提示','请选择一名学生');
					return;
				}
				studentSummary(selectedKeys[0]);
			}
		},'-',{
			text:'人生规划书',
			iconCls:'Applicationform',
			xtype:'button',
			handler:function(){
				var selectedKeys = grid.getSelectionModel().getSelection();
				if(selectedKeys.length != 1){
					Ext.MessageBox.alert('提示','请选择一名学生');
					return;
				}
				studentPlan(selectedKeys[0]);
			}
		}]		
	},
	{
		dock:'bottom',
		xtype:'pagingtoolbar',	
		store:store,
		displayInfo:true,
		displayMsg:'显示{0}-{1}条，共计{2}条',
		emptyMsg:"没有数据"
	},{
		dock:'bottom',
		xtype:'label',
		html:'<div style="font-size:12px;color:red">*双击可查看详细信息</div>'
	}]
});

function editStudent(){
	var selectedKeys = grid.getSelectionModel().getSelection();
	if(selectedKeys.length != 1){
		Ext.MessageBox.alert('提示','请选择一名学生');
	}else{
		var editStudent = Ext.create('Ext.Window',{
			layout:'fit',
			width:650,
			height:550,
			closeAction:'hide',
			plain:true,
			resizable : false,
			title:'学生相信信息',
			items:studentForm,
			plain:true
			
		});
	}
	editStudent.show();
	loadUser();
};
var sourseGrid = Ext.create('Ext.grid.Panel',{
	store:sourseStore,	
	columnLines:true,
	//selModel:checkBox,
	disableSelection:false,
	loadMask:true,
	columns:[
	         new Ext.grid.RowNumberer(),        
	         {text:'课程名',width:150,dataIndex:'courseName',sortable:true},
	         {text:'学时',width:100,dataIndex:'hourse',sortable:true},
	         {text:"学分",width:100,dataIndex:'credit',sortable:true},
	         {text:"平时成绩",width:100,dataIndex:'peacetimeScores',sortable:true},
	         {text:"考试成绩",width:100,dataIndex:'testScores',sortable:true},
	         {text:"总评成绩",width:100,dataIndex:'scores',sortable:true,
	        	 renderer : function(da){
        		 if(da < 60){
        			 return '<span style="color:red"><b>'+da+'</b></span>';
        		 }else{
        			 return da;
        		 }
        	 }},
	         {text:"其他",width:100,dataIndex:'isAgain',sortable:true,
	        	 renderer : function(da){
	        		 if(da == '1'){
	        			 return '<span style="color:red"><b>补</b></span>';
	        		 }else{
	        			 return "";
	        		 }
	        	 }}
	         ],
	autoHeight:true,
	authWidth:true,
	features: [{ 
		ftype: 'grouping' ,
		groupHeaderTpl:'学年: {name}    ---共{rows.length}条记录'
			}],
	title:"学生成绩信息",
	loadMask:true,

	dockedItems:[{
		dock:'top',
		xtype:'toolbar',		
		items:[{
			
				fieldLabel:'姓名',
				name:'studentId',
				id:'studentSourseNameId',
				xtype:'textfield',
				readOnly:true,
				labelWidth:'50px',
				labelAlign:'right'
		},{
			fieldLabel:'总学时',
			name:'totalHourse',
			id:'totalHourseId',
			xtype:'textfield',
			readOnly:true,
			labelWidth:'50px',
			labelAlign:'right'
		},{
			fieldLabel:'总学分',
			name:'totalCredit',
			id:'totalCreditId',
			xtype:'textfield',
			readOnly:true,
			labelWidth:'50px',
			labelAlign:'right'
		},{
			fieldLabel:'实获学分',
			name:'totalGetCredit',
			id:'totalGetCreditId',
			xtype:'textfield',
			readOnly:true,
			labelWidth:'60px',
			labelAlign:'right'
		}]		
	}]
});
function lookSourse(){
	var selectedKeys = grid.getSelectionModel().getSelection();
	if(selectedKeys.length != 1){
		Ext.MessageBox.alert('提示','请选择一名学生');
	}else{
		var studentId=selectedKeys[0].get("studentId");
		var editStudentSourse = Ext.create('Ext.Window',{
			layout:'fit',
			width:800,
			height:600,
			closeAction:'hide',
			plain:true,
			resizable : false,
			title:'学生成绩',
			items:sourseGrid,
			plain:true
			
		});
	}
	editStudentSourse.show();
	sourseStore.proxy.extraParams.jsonString="{'studentId':'"+studentId+"'}";
	sourseStore.load();
	//loadSourse();
};

function loadUser(){
	var selectedKeys = grid.getSelectionModel().getSelection();
	var studentId=selectedKeys[0].get("studentId");
	studentForm.form.load({					
		waitMsg : '正在加载数据请稍后',						
		url : 'searchStudentAction.action',			
		params:{studentId:studentId},				
		//method:'POST',//请求方式  
		failure : function(response, option) {
			Ext.Msg.alert("提示", "获取数据失败");
		},
		success : function(form, action) {
    		//var obj = action.result;
			//Ext.Msg.alert("提示",action.row);
			Ext.getCmp('image').getEl().dom.src=Ext.getCmp("photo").value;
    		//action.result.data.list.photo != null ? Ext.getCmp('image').getEl().dom.src= action.result.data.list.photo:"";
		}
});
};

function studentSummary(data){
	var teacherId = data.get("studentId");
	var tab = center.queryById("summaryListForTeaher"+teacherId);
    if (!tab) {
    	var tab = center.add({
    		id: 'summaryListForTeaher'+teacherId,
    		iconCls: 'Bookopen',       
    		xtype: "panel",
    		title: '学生总结',
    		closable: true,
    		//maskDiabled: true,
    		frame: true,
    		autoScroll : true,
    		region:center,
    		//baseCls:'allBackImage',
    		bodyStyle: 'background:white;',
    		items:new summaryListForTeacher(teacherId)
    		//html:'<iframe scrolling="auto" frameborder="0" width="100%" height="100%" src="'+url+'"></iframe>'
    	});  	
    }
    center.setActiveTab("summaryListForTeaher"+teacherId);
	
}
var state = {
		width: 500,
		xtype: 'displayfield',
		id: 'state',
		hidden:true,
		fieldLabel: 'state'	
};

var studentId = {
		width: 500,
		xtype: 'displayfield',
		id: 'studentIdForL',
		hidden:true,
		fieldLabel: 'studentId'	
};
var lpId = {
		width: 500,
		xtype: 'displayfield',
		id: 'lpId',
		hidden:true,
		fieldLabel: 'id'	
};

//备注
var remark ={
		//width: 500,
		xtype: 'textareafield',
		id: 'remark',
		rows:1,
		fieldLabel: '备注',
		readOnly:true
	};

//规划内容
var content = {
	id:'content_text',
    fieldLabel: '规划内容',
    xtype: 'htmleditor',
    height: 300,
    readOnly:true
};
//导师评语
var evaluate = {
		width: 500,
		xtype: 'textareafield',
		id: 'evaluate',
		rows:5,
		fieldLabel: '导师评语'	,
		maxLength:300
};
//创建时间
var createDate = {
		//width: 500,
		xtype: 'displayfield',
		id: 'createDate',
		
		fieldLabel: '创建时间'	
};
//创建时间
var endDate = {
		//width: 500,
		xtype: 'displayfield',
		id: 'endDate',
		hidden:true,
		fieldLabel: '最后时间'	
};
//修改时间
var doneDate = {
		//width: 500,
		xtype: 'displayfield',
		id: 'doneDate',
		
		fieldLabel: '修改时间'	
};
var Planpanel = new Ext.form.FormPanel( {
	id : "summaryPanel",
	layout : "form",
	items:[  
		{
			xtype:'label',
			html:'<center><div style="font-size:15px;"><b>人生规划书</b></div></center>'
		},
		studentId,
		createDate,
		doneDate,endDate,
       content,
       remark,
       evaluate,
       state,
       lpId
    ], 
    buttons : [ {
		xtype : "button",
		id:'saveBtn',
		text : "保存",
		pressed : false,
		handler : validatorData
	}],
	buttonAlign : "center"

});
function studentPlan(data){
	var studentPlanId = data.get("studentId");	
	var editStudentPlan = Ext.create('Ext.Window',{
		layout:'fit',
		width:800,
		height:600,
		closeAction:'hide',
		plain:true,
		resizable : false,
		title:'学生人生规划书',
		items:Planpanel,
		plain:true
		
	});
	editStudentPlan.show();
	Ext.Ajax.request( {
    	url : "searchStudentPlanAction.action", 
    	params : {
    		studentId:studentPlanId
    	}, //参数
    	success : function(response, option) {
    		
    		var obj = Ext.decode(response.responseText);
    		if(obj.list.length > 0){
    			Ext.getCmp("state").setValue(obj.list[0].state);
        		Ext.getCmp("lpId").setValue(obj.list[0].id);
        		Ext.getCmp("studentIdForL").setValue(obj.list[0].studentId);
        		Ext.getCmp("remark").setValue(obj.list[0].remark);
        		Ext.getCmp("content_text").setValue(obj.list[0].conentText);
        		Ext.getCmp("evaluate").setValue(obj.list[0].evaluate);
        		Ext.getCmp("createDate").setValue(obj.list[0].createDate==null?"":obj.list[0].createDate.replace("T"," "));
        		Ext.getCmp("doneDate").setValue(obj.list[0].doneDate==null?"":obj.list[0].doneDate.replace("T"," "));
        		Ext.getCmp("endDate").setValue(obj.list[0].modifyDateLimit==null?"":obj.list[0].modifyDateLimit.replace("T"," "));

    		}   		
    	},
    	failure : function(response, option) {
    		Ext.Msg.alert("失败", "系统错误");
    	}
   	});	
}
function validatorData() {		

	var evaluate = Ext.getCmp('evaluate').getValue();	
	var studentIdForL = Ext.getCmp('studentIdForL').getValue();
	var url = 'updateLifePlanByParamAction.action';
	Ext.Ajax.request({
			waitTitle : '提示',//标题
			waitMsg : '正在提交数据请稍后...',//提示信息
			url : url,
			method : 'post',
			params : {
				studentId:studentIdForL,
				//remark : remark,
				evaluate:evaluate
			}, //参数
			success : function(response, option) {
	    		
	    		var obj = Ext.decode(response.responseText);
				if (obj.success == true) {
					Ext.Msg.alert("提示", "保存成功！");
					//panel.getForm().reset();
				} else {
					Ext.Msg.alert("提示", "保存失败！");
				}
			},
			failure : function(form,action) {   
				Ext.Msg.alert("提示","保存失败！");	
			}
		});
		
}
return grid;
};
